// ----------------------------------
// RSDK Project: Sonic 2 - Boss Attack Plus
// Script Description: Attack Mode
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : object.timer
private alias object.value1 : start.fadeValue
private alias object.value2 : selection.current
private alias object.value3 : arrow.offset
private alias object.value4 : object.aniTileTImer
private alias object.value5 : object.aniTileFrame
private alias object.value6 : ranking.gamemode

// menu selections


//private alias 0 : 

// object states

private alias 0 : STARTING_UP
private alias 1 : FADE_IN
private alias 2 : CHAR_SELECT
private alias 3 : MENU_IDLE
private alias 4 : BACK_TO_TITLE
private alias 5 : RESET_TIME

// selections

private alias 0 : MODE
private alias 1 : RESET
private alias 2 : EXIT

// Game Modes

private alias 0 : BOTH
private alias 1 : S_ONE
private alias 2 : S_TWO

private alias saveRAM[494] : saved.bossGameMode //7B8 SData.bin
private alias saveRAM[495] : saved.bossType //7BC SData.bin
private alias saveRAM[496] : saved.BossMusic //7C0 SData.bin
private alias saveRAM[497] : saved.Character //7C4 SData.bin
private alias saveRAM[498] : saved.TimeLimit //7C8 SData.bin
private alias saveRAM[499] : saved.superMode //7CC SData.bin

private alias saveRAM[500] : bossAttackTime.SonicTails //7D0 SData.bin
private alias saveRAM[501] : bossAttackTime1.SonicTails //7D4 SData.bin
private alias saveRAM[502] : bossAttackTime2.SonicTails //7D8 SData.bin

private alias saveRAM[503] : bossAttackTime.Sonic //7DC SData.bin
private alias saveRAM[504] : bossAttackTime1.Sonic //7E0 SData.bin
private alias saveRAM[505] : bossAttackTime2.Sonic //7E4 SData.bin

private alias saveRAM[506] : bossAttackTime.Tails //7E8 SData.bin
private alias saveRAM[507] : bossAttackTime1.Tails //7EC SData.bin
private alias saveRAM[508] : bossAttackTime2.Tails //7F0 SData.bin

private alias saveRAM[509] : bossAttackTime.Knuckles //7F4 SData.bin
private alias saveRAM[510] : bossAttackTime1.Knuckles //7F8 SData.bin
private alias saveRAM[511] : bossAttackTime2.Knuckles //7FC SData.bin

private alias saveRAM[512] : bossAttackTime.KnucklesTails //800 SData.bin
private alias saveRAM[513] : bossAttackTime1.KnucklesTails //804 SData.bin
private alias saveRAM[514] : bossAttackTime2.KnucklesTails //808 SData.bin

private alias saveRAM[515] : bossAttackTime.SuperSonic //80C SData.bin
private alias saveRAM[516] : bossAttackTime1.SuperSonic //810 SData.bin
private alias saveRAM[517] : bossAttackTime2.SuperSonic //814 SData.bin

private alias saveRAM[518] : bossAttackTime.SuperTails //818SData.bin
private alias saveRAM[519] : bossAttackTime1.SuperTails //81C SData.bin
private alias saveRAM[520] : bossAttackTime2.SuperTails //820 SData.bin

private alias saveRAM[521] : bossAttackTime.SuperKnuckles //824 SData.bin
private alias saveRAM[522] : bossAttackTime1.SuperKnuckles //828 SData.bin
private alias saveRAM[523] : bossAttackTime2.SuperKnuckles //82C SData.bin

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//




//-------Functions-------//



event ObjectMain
	object.aniTileTImer++
	if object.aniTileTImer == 5
		object.aniTileTImer = 0
		object.aniTileFrame++
		object.aniTileFrame &= 7
		temp0 = object.aniTileFrame
		temp0 += 0x1C
		Copy16x16Tile(0x1B, temp0)
	end if

	switch object.state
	case STARTING_UP
		ReadSaveRAM()
		start.fadeValue = 276
		SetScreenFade(0, 0, 0, start.fadeValue)
		object.state = FADE_IN
		break
	case FADE_IN
		if start.fadeValue > 0
			start.fadeValue -= 12
		else
			start.fadeValue = 0
			object.state = MENU_IDLE
		endif
		SetScreenFade(0, 0, 0, start.fadeValue)
		break
	case MENU_IDLE
		if inputPress.down == 1
			if selection.current < 2
				selection.current ++
			else
				selection.current = 0
			endif
		endif
		if inputPress.up == 1
			if selection.current > 0
				selection.current --
			else
				selection.current = 2
			endif
		endif
		if inputPress.ButtonB == 1
			object.state = BACK_TO_TITLE
			selection.current = 0
		endif
		break
	case BACK_TO_TITLE
			SetScreenFade(0, 0, 0, start.fadeValue)
			start.fadeValue += 12
			music.volume -= 5
			if start.fadeValue >= 256
				temp4 = 0
				stage.activeList = PRESENTATION_STAGE
				stage.listPos = 3
				WritesaveRAM()
				LoadStage()
			endif
		break
	case RESET_TIME
		break
	endswitch

	switch selection.current
	case MODE
		if inputPress.right == 1
			if ranking.gamemode < 2
				ranking.gamemode ++
			else
				ranking.gamemode = 0
			endif
		endif
		if inputPress.left == 1
			if ranking.gamemode > 0
				ranking.gamemode --
			else
				ranking.gamemode = 2
			endif
		endif
		break
	case RESET
		if inputPress.ButtonA == 1
			object.state = RESET_TIME
			object[+1].state = 2
		endif
		break
	case EXIT
		WriteSaveRAM()
		if inputPress.ButtonA == 1
			object.state = BACK_TO_TITLE
		endif
		break
	endswitch
end event

event ObjectDraw
	if object.timer > 7
		object.timer = 0
		object.frame ^= 1
	else
		object.timer++
	endif
//----------------------HEADER------------------------------------

	temp1 = 16
	DrawSpriteScreenXY(0, screen.xcenter, temp1)

//----------------------CHARACTER SELECT--------------------------

	temp1 += 36
	temp2 = object.frame
	temp2 += 26
	if selection.current == MODE
		DrawSpriteScreenXY(temp2, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(26, screen.xcenter, temp1)
	endif

//----------------------MODE--------------------------------------

	temp1 -= 4
	if selection.current != MODE
		DrawSpriteScreenXY(1, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(2, screen.xcenter, temp1)
	endif
	temp1 += 8

	switch ranking.gamemode
	case 0
		DrawSpriteScreenFX(23, FX_INK, screen.xcenter, temp1) //S1+S2
		object[+5].state = 1
		object[+6].state = 1
		break
	case 1
		DrawSpriteScreenFX(24, FX_INK, screen.xcenter, temp1) //S1
		object[+5].state = 1
		object[+6].state = 0
		break
	case 2
		DrawSpriteScreenFX(25, FX_INK, screen.xcenter, temp1) //S2
		object[+5].state = 0
		object[+6].state = 1
		break
	endswitch

//----------------------SONIC-------------------------------------

	temp1 += 32
	DrawSpriteScreenXY(7, screen.xcenter, temp1)
	DrawSpriteScreenXY(11, screen.xcenter, temp1)
	DrawSpriteScreenXY(12, screen.xcenter, temp1)

	switch ranking.gamemode
	case BOTH
		temp5 = bossAttackTime.Sonic
		break
	case S_ONE
		temp5 = bossAttackTime1.Sonic
		break
	case S_TWO
		temp5 = bossAttackTime2.Sonic
		break
	endswitch

		temp3 = temp5
		temp3 /= 0x1770
		stage.minutes = temp3
		temp3 = temp5
		temp2 = 0x1770
		temp2 *= stage.minutes
		temp3 -= temp2
		temp3 /= 100
		stage.seconds = temp3
		stage.milliseconds = temp5

		temp4 = 268
		DrawNumbers(13, temp4, temp1, stage.minutes, 2, 8, 1)
		temp4 += 20
		DrawNumbers(13, temp4, temp1, stage.seconds, 2, 8, 1)
		temp4 += 24
		DrawNumbers(13, temp4, temp1, stage.milliseconds, 2, 8, 1)


//----------------------TAILS-------------------------------------

	temp1 += 16
	DrawSpriteScreenXY(8, screen.xcenter, temp1)
	DrawSpriteScreenXY(11, screen.xcenter, temp1)
	DrawSpriteScreenXY(12, screen.xcenter, temp1)

	switch ranking.gamemode
	case BOTH
		temp5 = bossAttackTime.Tails
		break
	case S_ONE
		temp5 = bossAttackTime1.Tails
		break
	case S_TWO
		temp5 = bossAttackTime2.Tails
		break
	endswitch

		temp3 = temp5
		temp3 /= 0x1770
		stage.minutes = temp3
		temp3 = temp5
		temp2 = 0x1770
		temp2 *= stage.minutes
		temp3 -= temp2
		temp3 /= 100
		stage.seconds = temp3
		stage.milliseconds = temp5

		temp4 = 268
		DrawNumbers(13, temp4, temp1, stage.minutes, 2, 8, 1)
		temp4 += 20
		DrawNumbers(13, temp4, temp1, stage.seconds, 2, 8, 1)
		temp4 += 24
		DrawNumbers(13, temp4, temp1, stage.milliseconds, 2, 8, 1)

//----------------------KNUCKLES----------------------------------

	temp1 += 16
	DrawSpriteScreenXY(9, screen.xcenter, temp1)
	DrawSpriteScreenXY(11, screen.xcenter, temp1)
	DrawSpriteScreenXY(12, screen.xcenter, temp1)


	switch ranking.gamemode
	case BOTH
		temp5 = bossAttackTime.Knuckles
		break
	case S_ONE
		temp5 = bossAttackTime1.Knuckles
		break
	case S_TWO
		temp5 = bossAttackTime2.Knuckles
		break
	endswitch

		temp3 = temp5
		temp3 /= 0x1770
		stage.minutes = temp3
		temp3 = temp5
		temp2 = 0x1770
		temp2 *= stage.minutes
		temp3 -= temp2
		temp3 /= 100
		stage.seconds = temp3
		stage.milliseconds = temp5

		temp4 = 268
		DrawNumbers(13, temp4, temp1, stage.minutes, 2, 8, 1)
		temp4 += 20
		DrawNumbers(13, temp4, temp1, stage.seconds, 2, 8, 1)
		temp4 += 24
		DrawNumbers(13, temp4, temp1, stage.milliseconds, 2, 8, 1)

//----------------------SONIC-&-TAILS-----------------------------

	temp1 += 16
	DrawSpriteScreenXY(7, screen.xcenter, temp1)
	DrawSpriteScreenXY(11, screen.xcenter, temp1)
	DrawSpriteScreenXY(12, screen.xcenter, temp1)
	temp0 = screen.xcenter
	temp0 += 8
	DrawSpriteScreenXY(10, temp0, temp1)


	switch ranking.gamemode
	case BOTH
		temp5 = bossAttackTime.SonicTails
		break
	case S_ONE
		temp5 = bossAttackTime1.SonicTails
		break
	case S_TWO
		temp5 = bossAttackTime2.SonicTails
		break
	endswitch

		temp3 = temp5
		temp3 /= 0x1770
		stage.minutes = temp3
		temp3 = temp5
		temp2 = 0x1770
		temp2 *= stage.minutes
		temp3 -= temp2
		temp3 /= 100
		stage.seconds = temp3
		stage.milliseconds = temp5

		temp4 = 268
		DrawNumbers(13, temp4, temp1, stage.minutes, 2, 8, 1)
		temp4 += 20
		DrawNumbers(13, temp4, temp1, stage.seconds, 2, 8, 1)
		temp4 += 24
		DrawNumbers(13, temp4, temp1, stage.milliseconds, 2, 8, 1)

//----------------------KNUCKLES-&-TAILS--------------------------

	temp1 += 16
	DrawSpriteScreenXY(9, screen.xcenter, temp1)
	DrawSpriteScreenXY(11, screen.xcenter, temp1)
	DrawSpriteScreenXY(12, screen.xcenter, temp1)
	temp0 = screen.xcenter
	temp0 += 32
	DrawSpriteScreenXY(10, temp0, temp1)


	switch ranking.gamemode
	case BOTH
		temp5 = bossAttackTime.KnucklesTails
		break
	case S_ONE
		temp5 = bossAttackTime1.KnucklesTails
		break
	case S_TWO
		temp5 = bossAttackTime2.KnucklesTails
		break
	endswitch

		temp3 = temp5
		temp3 /= 0x1770
		stage.minutes = temp3
		temp3 = temp5
		temp2 = 0x1770
		temp2 *= stage.minutes
		temp3 -= temp2
		temp3 /= 100
		stage.seconds = temp3
		stage.milliseconds = temp5

		temp4 = 268
		DrawNumbers(13, temp4, temp1, stage.minutes, 2, 8, 1)
		temp4 += 20
		DrawNumbers(13, temp4, temp1, stage.seconds, 2, 8, 1)
		temp4 += 24
		DrawNumbers(13, temp4, temp1, stage.milliseconds, 2, 8, 1)

//----------------------RESET-------------------------------------

	temp1 += 42
	if selection.current != 1
		DrawSpriteScreenXY(3, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(4, screen.xcenter, temp1)
	endif

//----------------------BACK--------------------------------------

	temp1 += 16
	if selection.current != 2
		DrawSpriteScreenXY(5, screen.xcenter, temp1)
	else
		DrawSpriteScreenXY(6, screen.xcenter, temp1)
	endif
end event

event ObjectStartup
	ReadSaveRAM()
	//tileLayer[1].scrollPos = 0xa00000
	if stage.listPos == 1
		Stage[0].ActiveLayer=2
		SetMusicTrack("BossS1.ogg", 0, 1)
	endif
	PlayMusic(0)

	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-52, -7, 104, 14, 256, 136)			//00 RANKING HEADER

	SpriteFrame(-16, -3, 32, 7, 249, 494)			//01 MODE
	SpriteFrame(-16, -3, 32, 7, 216, 494)			//02 MODE Yellow

	SpriteFrame(-20, -3, 40, 7, 282, 494)			//03 RESET
	SpriteFrame(-20, -3, 40, 7, 315, 502)			//04 RESET Yellow

	SpriteFrame(-16, -3, 32, 7, 249, 502)			//05 BACK
	SpriteFrame(-16, -3, 32, 7, 282, 502)			//06 BACK Yellow

	SpriteFrame(-50, -3, 40, 7, 240, 406)			//07 SONIC
	SpriteFrame(-50, -3, 40, 7, 240, 414)			//08 TAILS
	SpriteFrame(-50, -3, 64, 7, 240, 422)			//09 KNUCKLES
	SpriteFrame(-50, -3, 40, 14, 305, 422)			//10 &TAILS

	SpriteFrame(64, -3, 3, 7, 164, 140)			//11 '
	SpriteFrame(85, -3, 6, 7, 164, 140)			//12 ''

	SpriteFrame(0, -3, 8, 7, 175, 140)			//13 0
	SpriteFrame(0, -3, 8, 7, 183, 140)			//14 1
	SpriteFrame(0, -3, 8, 7, 191, 140)			//15 2
	SpriteFrame(0, -3, 8, 7, 199, 140)			//16 3
	SpriteFrame(0, -3, 8, 7, 207, 140)			//17 4
	SpriteFrame(0, -3, 8, 7, 215, 140)			//18 5
	SpriteFrame(0, -3, 8, 7, 223, 140)			//19 6
	SpriteFrame(0, -3, 8, 7, 231, 140)			//20 7
	SpriteFrame(0, -3, 8, 7, 239, 140)			//21 8
	SpriteFrame(0, -3, 8, 7, 247, 140)			//22 9

	SpriteFrame(-22, -3, 44, 7, 34, 453)			//23 S1&S2
	SpriteFrame(-8, -3, 16, 7, 83, 414)			//24 S1
	SpriteFrame(-8, -3, 16, 7, 83, 422)			//25 S2

	SpriteFrame(-32, -12, 64, 25, 229, 238)			//26 Yellow Box
	SpriteFrame(-32, -12, 64, 25, 229, 264)			//27 Red Box
end event

event RSDKDraw
    DrawSprite(0)
end event

event RSDKLoad
    LoadSpriteSheet("Global/Display.gif")
    SpriteFrame(-16, -16, 32, 32, 223, 172)
end event